<?php
if ( is_array( $contacts ) and ( count( $contacts ) > 0 )) {
    echo '<table class="contact_list">'."\n";
    echo '<tr>'."\n";
    echo "\t".'<th>First Name</th>'."\n";
    echo "\t".'<th>Last Name</th>'."\n";
    echo "\t".'<th>Email</th>'."\n";
    echo "\t".'<th>Phone</th>'."\n";
    echo "\t".'<th></th>'."\n";
    echo '</tr>'."\n";
    foreach ( $contacts as $c ) {
        echo '<tr>'."\n";
        echo "\t".'<td>'.$c[ 'fname' ].'</td>'."\n";
        echo "\t".'<td>'.$c[ 'lname' ].'</td>'."\n";
        echo "\t".'<td>'.$c[ 'email' ].'</td>'."\n";
        echo "\t".'<td>'.$c[ 'phone' ].'</td>'."\n";
        echo "\t".'<td><a class="edit_hidden" href="edit.php?id='.$c[ 'rowid' ].'">edit</a></td>'."\n";
        echo '</tr>'."\n";
    }
    echo '</table>'."\n";
} else {
    echo '<p style="color: rgb(127, 127, 127);">';
    if ( $_SESSION[ 'filter' ] ) {
        echo 'There are no contacts that match the search terms ('.$_SESSION[ 'filter' ].').';
    } else {
        echo 'There are no contacts in the list.';
    }
    echo '</p>'."\n";
}


echo '<div class="actions">'."\n";
echo '<form action="'.$script_name.'" method="get">'."\n";
echo '<input type="text" name="filter_terms" value="'.$_SESSION[ 'filter' ].'" />'."\n";
echo '<button type="Submit" name="action" value="filter">Filter</button>'."\n";
if ( $_SESSION[ 'filter' ] ) {
} 
echo '<button type="Submit" name="action" value="add">New contact</button>'."\n";
echo '</form>'."\n";
echo '</div>'."\n";
?>

